package data;

import utils.Utils;

public class Data {

	String dataName;
	String[] columnNames;
	double[][] data;
	
	public Data(String dataName, String[] columnNames, double[][] data){
		this.dataName = dataName;
		this.columnNames = columnNames;
	}
	
	public Data(String dataName, String[] columnNames, double[] independent, double[][] dependents){
		this.dataName = dataName;
		this.columnNames = columnNames;
		
		data = new double[dependents.length+1][];
		data[0] = independent;
		for(int i=1;i<data.length;i++){
			data[i] = dependents[i-1];
		}
		
	}

	public static Data readDataFromFile(String dataName, String filename) {
		String[] columnNames = Utils.getFileHeader(filename);
		double[][] dDataArray = Utils.convertToDoubles(Utils.transposeArray(Utils.readAndSkipLines(filename, 1)));
		double[][] dependents = Utils.dropColumn(dDataArray, 1); 
		return new Data(dataName, columnNames, dDataArray[0], dependents);
	}

	public String getDataName() {
		return dataName;
	}

	public String[] getColumnNames() {
		return columnNames;
	}

	public double[] getIndependent() {
		return data[0];
	}

	public double[][] getDependents() {
		return Utils.dropColumn(data, 1);
	}
	
	public double[] getDataColumn(int column){
		if(column < 0 || column > data.length -1){
			return null;
		}else{
			return data[column];
		}
	}
	
	
}
